//
//  TeamTableViewCell.m
//  MeterMart
//
//  Created by ENERGY on 2018/10/23.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "TeamTableViewCell.h"

@interface TeamTableViewCell ()
@property (nonatomic, strong)UIView * whiteBGView;
@property (nonatomic, strong)UIImageView * iconImg;
@property (nonatomic, strong)UILabel * nameLab;
@property (nonatomic, strong)UILabel * numLab;
@property (nonatomic, strong)UILabel * statusLab;
@end

@implementation TeamTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        __weak typeof (self)weakSelf = self;
        self.contentView.backgroundColor = getColor(mainColor);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.whiteBGView];
        [self.whiteBGView addSubview:self.iconImg];
        [self.whiteBGView addSubview:self.nameLab];
        [self.whiteBGView addSubview:self.numLab];
        [self.whiteBGView addSubview:self.statusLab];
        
        [self.whiteBGView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView.mas_left).mas_offset(10/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.contentView.mas_top).mas_offset(10/WIDTH_6_SCALE);
            make.right.equalTo(weakSelf.contentView.mas_right).mas_offset(-10/WIDTH_6_SCALE);
            make.bottom.equalTo(weakSelf.contentView.mas_bottom);
        }];
        [self.iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.whiteBGView.mas_left).mas_offset(21/WIDTH_6_SCALE);
            make.centerY.equalTo(weakSelf.whiteBGView.mas_centerY);
            make.width.height.mas_offset(57/WIDTH_6_SCALE);
        }];
        [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.iconImg.mas_right).mas_offset(20/WIDTH_6_SCALE);
            make.bottom.equalTo(weakSelf.iconImg.mas_centerY);
        }];
        [self.numLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.nameLab.mas_bottom).mas_offset(13/WIDTH_6_SCALE);
            make.left.equalTo(weakSelf.nameLab.mas_left);
        }];
        [self.statusLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.whiteBGView.mas_right).mas_offset(-22/WIDTH_6_SCALE);
            make.centerY.equalTo(weakSelf.nameLab.mas_centerY);
        }];
    }return self;
}
- (UIView *)whiteBGView{
    if (!_whiteBGView) {
        _whiteBGView = [[UIView alloc] init];
        _whiteBGView.backgroundColor = [UIColor whiteColor];
    }return _whiteBGView;
}
- (UIImageView *)iconImg{
    if (!_iconImg) {
        _iconImg = [[UIImageView alloc] init];
//        _iconImg.backgroundColor = [UIColor orangeColor];
        _iconImg.image = [UIImage imageNamed:@"YimiPlaceHolderCircle"];
    }return _iconImg;
}
- (UILabel *)nameLab{
    if (!_nameLab) {
        _nameLab = [[UILabel alloc] init];
        _nameLab.font = DEF_FontSize_15;
        _nameLab.textColor = [UIColor blackColor];
        _nameLab.textAlignment = NSTextAlignmentLeft;
        _nameLab.text = @"微信名称";
    }return _nameLab;
}
- (UILabel *)numLab{
    if (!_numLab) {
        _numLab = [[UILabel alloc] init];
        _numLab.font = DEF_FontSize_13;
        _numLab.textColor = getColor(textGrayColor);
        _numLab.textAlignment = NSTextAlignmentLeft;
        _numLab.text = [NSString stringWithFormat:@"编号:%@", @"---"];
    }return _numLab;
}
- (UILabel *)statusLab{
    if (!_statusLab) {
        _statusLab = [[UILabel alloc] init];
        _statusLab.font = DEF_FontSize_13;
        _statusLab.textColor = [UIColor blackColor];
        _statusLab.textAlignment = NSTextAlignmentRight;
        _statusLab.text = @"已生效";
    }return _statusLab;
}

- (void)setModel:(NSDictionary *)model{
    _model = model;
    self.nameLab.text = model[@"username"];
    self.numLab.text = model[@"agentnum"];
    self.statusLab.text = model[@"userlevel"];
    if ([model[@"userlevel"] isEqualToString:@"0"]) {
        self.statusLab.text = @"未生效";
    }else{
        self.statusLab.text = @"已生效";
    }
    [self.iconImg sd_setImageWithURL:model[@"headimg"] placeholderImage:[UIImage imageNamed:@"YimiPlaceHolderCircle"]];
}
@end
